package chapter02;

import java.util.Scanner;

public class supermarket {
    public static void main(String[] args) {
        double yashua = 8.8;
        double maojin = 10.0;
        double shuibei = 12.5;
        double pingguo = 12.5;
        double xiangjiao = 15.5;
        System.out.println("----------黑马小商城--------");
        System.out.println("1.牙刷的价格为：8.8元");
        System.out.println("2.毛巾的价格为：10.0元");
        System.out.println("3.水杯的价格为：18.8元");
        System.out.println("4.苹果的价格为：12.5元");
        System.out.println("5.香蕉的价格为：15.5元");

        //循环开始前准备工作
        String xuanze = "Y";//一种数据类型 存放字符串 默认选购
        double zongjia = 0;//总价一般放在循环外部
        Scanner scl = new Scanner(System.in);//用来获取输入
        //不知道用户需要循环几次 可能无限次 使用while或者do while
        while (xuanze.equals("Y")){//Sting不支持 xuanze == "Y"
            System.out.println("请输入你需要购买的序列号");
            int xuHao = scl.nextInt();//获取输入的序列号
            //判断目录输入的序号 进行不同价格计算
            if (xuHao == 1){
                System.out.println("请输入你要购买的牙刷数量");
                int yashuaShuliang = scl.nextInt();
                //加上以前累计购买商品的价格 放入总价
                zongjia = zongjia + yashua*yashuaShuliang;
                System.out.println("你购买了牙刷"+ yashuaShuliang+
                        "只,需要花费"+ yashua * yashuaShuliang+"元");
            }else if (xuHao == 2){
                System.out.println("请输入你要购买的毛巾数量");
                int maojinShuliang = scl.nextInt();
                //加上以前累计购买商品的价格 放入总价
                zongjia = zongjia + maojin*maojinShuliang;
                System.out.println("你购买了毛巾"+ maojinShuliang+
                        "只,需要花费"+ maojin  * maojinShuliang+"元");
            }else if (xuHao == 3){
                System.out.println("请输入你要购买的水杯数量");
                int shuibeiShuliang = scl.nextInt();
                //加上以前累计购买商品的价格 放入总价
                zongjia = zongjia + shuibei*shuibeiShuliang;
                System.out.println("你购买了水杯"+ shuibeiShuliang+
                        "只,需要花费"+ shuibei  * shuibeiShuliang+"元");
            }else if (xuHao == 4){
                System.out.println("请输入你要购买的苹果数量");
                int pingguoShuliang = scl.nextInt();
                //加上以前累计购买商品的价格 放入总价
                zongjia = zongjia + pingguo*pingguoShuliang;
                System.out.println("你购买了苹果"+ pingguoShuliang+
                        "只,需要花费"+ pingguo  * pingguoShuliang+"元");
            }else if (xuHao == 5){
                System.out.println("请输入你要购买的香蕉数量");
                int xiangjiaoShuliang = scl.nextInt();
                //加上以前累计购买商品的价格 放入总价
                zongjia = zongjia + xiangjiao*xiangjiaoShuliang;
                System.out.println("你购买了香蕉"+ xiangjiaoShuliang+
                        "只,需要花费"+ xiangjiao  * xiangjiaoShuliang+"元");
            }else{

            }
            //让用户选择是否继续购买
            System.out.println( "需要继续购买输入Y，否则输入N");
            xuanze = scl.next();
        }
    }
}
